<template>
  <div class="active" @click="to('/pages-sub/activity/detail', { id: data.id })">
    <div class="img">
      <image :src="imgUrls[0]" mode="aspectFill" />
      <div class="status" :class="{ not: statusMode.status !== 1 }">{{ statusMode.text }}</div>
    </div>
    <div class="info">
      <div>
        <div class="title">{{ data.title }}</div>
        <div class="tips">{{ data.addr }}</div>
        <div class="tips">{{ day }}</div>
      </div>
      <div v-if="data.attend.id">
        <div class="button">已报名</div>
      </div>
      <div v-else-if="statusMode.status === 1">
        <div class="button">参与活动</div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { activityStatus } from './utils'
import dayjs from 'dayjs'
import { to } from '@/utils/page'
defineOptions({ name: 'Active' })

const props = defineProps(['data'])

const imgUrls = ref([])
const day = ref('')
const statusMode = ref<any>({})
if (props.data.imgUrls) {
  imgUrls.value = props.data.imgUrls.split(',')
  day.value = `${dayjs(props.data.startTime).format('MM-DD HH:MM')} - ${dayjs(props.data.endTime).format('MM-DD HH:MM')}`
}
statusMode.value = activityStatus(props.data)
</script>
<style lang="scss" scoped>
.active {
  display: flex;
  padding-bottom: 30rpx;
  margin-bottom: 30rpx;
  @include border-bottom(#dfe3e6);
  .img {
    position: relative;
    width: 212rpx;
    height: 212rpx;
    overflow: hidden;
    border-radius: 19rpx;
    image {
      width: 100%;
      height: 100%;
      border-radius: 19rpx;
    }
    .status {
      position: absolute;
      top: 0;
      left: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 80rpx;
      height: 42rpx;
      font-size: 19rpx;
      color: #fff;
      background-color: var(--sc4);
      border-radius: 22rpx 0 22rpx 0;
      &.not {
        background-color: rgba(#979797, 0.8);
      }
    }
  }
  .info {
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: space-between;
    margin-left: 20rpx;
    .title {
      padding-top: 10rpx;
      margin-bottom: 10rpx;
      font-size: 27rpx;
      font-weight: 600;
      line-height: 32rpx;
      color: var(--color1);
      @include text-clamp();
    }
    .tips {
      margin-top: 8rpx;
      font-size: 23rpx;
      line-height: 27rpx;
      color: var(--color4);
      @include text-clamp();
    }
    .button {
      display: inline-flex;
      align-items: center;
      height: 54rpx;
      padding: 0 20rpx;
      font-size: 20rpx;
      color: #fff;
      background-color: var(--color1);
      border-radius: 27rpx;
    }
  }
  &:last-child {
    padding-bottom: 0;
    margin-bottom: 0;
    @include border-bottom(transparent);
  }
}
</style>
